<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
	<head>
		<title>JavaScript Constructor Lab1</title>
		<style type="text/css">
			div#header {
				color: #0066FF;
				font-size: 25pt;
			}
			
			div#content {
				color: #B088FF;
				font-size: 12pt;
			}
		</style>
		<!-- embed jquery by google，藉由google嵌入jquery 1.4.4 -->
		<script type="text/javascript" src="http://www.google.com/jsapi"></script>
		<script type="text/javascript" language="javascript">
			google.load( "jquery", "1.4.4" );
		</script>
		<script type="text/javascript">
			$( document ).ready( function() {
				
				// 建構子函式
				function Person( name, age ) {
					this.name     = name;
					this.age      = age;
					this.toString = function() {
						return "[name: " + this.name + ", age: " + this.age + "]";
					};
				}
				
				var p = new Person( "Vivian", 22 );
				if( p.constructor === Person ) {
					alert( "\"p.constructor === Person\" is true" );  // 印出
				} else {
					alert( "\"p.constructor === Person\" is false" );
				}
				var info = p.toString();
				$( "#header" ).html( info );
				
				/**********************************************************/
				
				// 指派一個建構子函式
				var CreateIntArray = function() {
					return [1, 2, 3, 4, 5, 6];
				};
				
				var c = new CreateIntArray();
				if( c instanceof CreateIntArray ) {
					alert( "\"c instanceof CreateIntArray\" is true" );
				} else {
					alert( "\"c instanceof CreateIntArray\" is false" );  // 印出
				}
				
				if( c instanceof Array ) {
					alert( "\"c instanceof Array\" is true" );  // 印出
				} else {
					alert( "\"c instanceof Array\" is false" );
				}
				
				
				/**********************************************************/
				
				var SuperMan = function( name, age ) {
					this.name = name;
					this.age = age;
					this.toString = function() {
						return "[name: " + this.name + ", age: " + this.age + "]";
					};
					return this;  // 回傳this所參照到的物件
				};
				
				var s = {};
				s = SuperMan.call( s, "Yoha", "87465798" );  // what is call() function???
				var whatIsTheType = typeof( s );
				alert( "typeof( s ):  " + whatIsTheType );
				
				if( s instanceof SuperMan ) {
					alert( "\"s instanceof SuperMan\" is true" );
				} else {
					alert( "\"s instanceof SuperMan\" is false" );  // 印出
				}
				
				var infoOfSuperMan = s.toString();
				alert( "Info of SuperMan: " + infoOfSuperMan );
				
				/*******************************************************
				筆記: 有關javascript的call()函式
				call( thisObj, [arg1, arg2, arg3])  方法調用
				
				第一個參數: thisObj
				在call()函式中，this所參考的物件
				參考: http://xiaofeizm55333.iteye.com/blog/80913
				
				********************************************************/
				
				
				/**********************************************************/
				
				var Animal = function( weight ) {
					this.weight = weight;
				};
				
				var a = new Animal( 100 );
				if( a.constructor === Animal ) {
					alert( "\"a.constructor === Animal\" is true" );  // 印出
				} else {
					alert( "\"a.constructor === Animal\" is false" );
				}
				
			});
		</script>
		
	</head>
	
	<body>
		<div title="temp1" id="header">Hello HTML</div>
		<div title="temp1" id="content">Here is content</div>
	</body>
</html>